function [OlS_1Y Ri RI varben] = MyP1BetaKF(Pi, PI)

    % Computation Time Series
    Ri = Pi(2:end)./Pi(1:(end - 1)) - 1;
    RI = PI(2:end)./PI(1:(end - 1)) - 1;
    %Stima OLS
    RI_Var = RI;

    %-----------------------------------------------------------
    %OLS 1 Year + Rolling window
    rolling = 260;
    [n, m] = size(Ri);
    k = n - rolling;

    for i = 1:k
        j = i + rolling;
        Ri_OlS = Ri(i:j);
        RI_OlS = RI(i:j);
        RI_OLS_Var = RI_Var(i:j);
        
       [n, m] = size(Ri_OlS);
        X = [ones(n,1), RI_OlS];
        y = Ri_OlS;
        
        %QR Decomposition X
        [Q, R] = qr(X, 0);
        
        %Regression Coefficients 
        beta = R \ (Q' * y);
        
        %Fitted Values of the Response 
        yhat = X * beta;
        
        %Residuals
        residuals = y - yhat;
        %residualsm(i) = mean(residuals);
        
        %Mean Squared Error 
        n_obs = length(y);
        p = min(size(R));
        DFE = n_obs - p;
        mse = sum(residuals.* residuals)./ DFE;
        
        %Hat (Projection) Matrix 
        hatmat = Q * Q';
        yhat = hatmat * y;
        
        %Covariance Matrix of Estimated Coefficients 
        ri = eye(p) / R; % inverse of R
        cov_b = ri * ri' * mse;%(i);
        
        %Student's t statistics 
        coeff(i, :) = (R \ (Q' * y))';
        se = sqrt(diag(cov_b));
        t(i, :) = coeff(i, :)./ se';
        pval(i,:) = (tcdf(-abs(t(i, :)), DFE)).* 2;
        
        %F statistic 
        SSE  = norm(residuals).^2  ;
        SSR  = norm(yhat - mean(yhat)).^2;
        FDFE  =  n_obs - p;
        DFR  = p - 1;
        f = (SSR / DFR)./ (SSE / DFE);
        pfval(i) = 1 - fcdf(f, DFR, DFE);
        varben(i) = var(RI_OLS_Var); 
    end
    beta1 = coeff(:,2);
    %-----------------------------------------------------------
    %---Download Excell
    OlS_1Y = [beta1, t(:,2), pval(:,2)];
end

